<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">

      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称（英文）" prop="itemNameEn">
        <el-input
          v-model="queryParams.itemNameEn"
          placeholder="请输入物料名称（英文）"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料识别码" prop="itemIdentifyCode">
        <el-input
          v-model="queryParams.itemIdentifyCode"
          placeholder="请输入物料识别码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="物料分类" prop="classId">
        <el-select style="width: 100%" v-model="queryParams.classId" placeholder="请选择物料分类" >
          <el-option
            v-for="dict in classOptions"
            :key="dict.classId"
            :label="dict.className"
            :value="dict.classId"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>


      <el-form-item label="供应商" prop="supplyId">
        <el-select style="width: 100%" v-model="queryParams.supplyId" placeholder="供应商" >
          <el-option
            v-for="dict in supplyOptions"
            :key="dict.id"
            :label="dict.supplyName"
            :value="dict.id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['base:iteminfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['base:iteminfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['base:iteminfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleDeleteAll"
          v-hasPermi="['base:itembzinfo:removeAll']"
        >全部删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['base:iteminfo:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          :disabled="multiple"
          icon="el-icon-printer"
          size="mini"
          @click="printtt"
        >打印</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table height="calc(100vh - 300px)" v-loading="loading" :data="iteminfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司代码" align="center" prop="factoryCode"  class-name="small-padding fixed-width" fixed="left" />
      <el-table-column label="公司名称" align="center" prop="factoryName" class-name="small-padding fixed-width" fixed="left"  />
      <el-table-column width="220" label="物料编号" align="center" prop="itemCode" />
      <el-table-column width="220" label="物料子编号" align="center" prop="itemId" />
      <el-table-column label="物料名称" width="220" show-overflow-tooltip align="center" prop="itemName" />
      <el-table-column label="物料名称（英文）" width="220" show-overflow-tooltip align="center" prop="itemNameEn" />
      <!--      <el-table-column label="物料识别码" width="250" show-overflow-tooltip align="center" prop="itemIdentifyCode" />-->
      <el-table-column label="物料单位" align="center" prop="unit">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.jc_iteminfo_unit" :value="scope.row.unit"/>
        </template>
      </el-table-column>
      <el-table-column label="规格型号" show-overflow-tooltip   align="center" prop="spec" width="220" />
      <el-table-column width="150" label="条码号" align="center" prop="tmh"/>
      <el-table-column label="成本价" align="center" prop="price" />
      <el-table-column label="物料分类编码" align="center" prop="classId" />
      <el-table-column label="物料分类名称" align="center" prop="className" />
      <el-table-column label="物料大类编码" align="center" prop="classBigId" />
      <el-table-column label="物料大类名称" align="center" prop="classBigName" />
      <el-table-column label="供应商编码" align="center" prop="supplyId" />
      <el-table-column label="供应商名称" align="center" prop="supplyName" />
      <el-table-column label="供应商类别" align="center" prop="supplyType" />
      <el-table-column label="供应商简称" align="center" prop="supplyJc" />
      <!--      <el-table-column label="预警上线" align="center" prop="upLine" />-->
      <!--      <el-table-column label="预警下线" align="center" prop="downLine" />-->
      <!--      <el-table-column label="中间值" align="center" prop="middleLine" />-->
      <!--      <el-table-column label="存储期" align="center" prop="cunchudate" />-->
      <!--      <el-table-column label="保质期" align="center" prop="productiondate" />-->
      <!--      <el-table-column label="尺寸" align="center" prop="size" />-->
      <!--      <el-table-column label="单重" align="center" prop="singleWeight" />-->
      <!--      <el-table-column label="使用状态" align="center" prop="useState" />-->
      <!--      <el-table-column label="颜色" align="center" prop="color" />-->
      <!--      <el-table-column label="花纹" align="center" prop="figure" />-->
      <!--      <el-table-column label="材质" align="center" prop="caizhi" />-->
      <!--      <el-table-column label="包装数量" align="center" prop="baozhuangQty" />-->
      <!--      <el-table-column label="包装方式" align="center" prop="baozhuangType">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.jc_iteminfo_bz" :value="scope.row.baozhuangType"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="物料状态" align="center" prop="stopFlag">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.jc_iteminfo_stop" :value="scope.row.stopFlag"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="组织机构" align="center" prop="deptId" />-->
      <!--      <el-table-column label="托管状态" align="center" prop="isTuoguan">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.is_tuoguan" :value="scope.row.isTuoguan"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <!--      <el-table-column label="计划价" align="center" prop="jhPrice" />-->
      <!--      <el-table-column label="合同价" align="center" prop="htPrice" />-->
      <!--      <el-table-column label="发票价" align="center" prop="fpPrice" />-->
      <!--      <el-table-column label="结算价" align="center" prop="jsPrice" />-->
      <!--      <el-table-column label="生产周期" align="center" prop="proCycle" />-->
      <!--      <el-table-column label="供货周期" align="center" prop="deliveryCycle" />-->
      <!--      <el-table-column label="供货份额" align="center" prop="deliveryFe" />-->
      <!--      <el-table-column label="份额调整比例" align="center" prop="adjustRate" />-->
      <!--      <el-table-column label="份额调整日期" align="center" prop="adjustDate" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.adjustDate, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="月订单数量" align="center" prop="yddNum" />-->
      <!--      <el-table-column label="月完成数量" align="center" prop="ywcNum" />-->
      <!--      <el-table-column label="月度供货未完成比率" align="center" prop="yghwwcRate" />-->
      <!--      <el-table-column label="生产线简码" align="center" prop="lineSimpleCode" />-->
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" fixed="right" width="120" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['base:iteminfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['base:iteminfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改物料信息对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <!--     <el-row>
               <el-col :span="12">
                 <el-form-item label="公司代码" prop="factoryCode">
                   <el-input v-model="form.factoryCode" placeholder="请输入公司代码" />
                 </el-form-item>
               </el-col>
               <el-col :span="12">
                 <el-form-item label="公司名称" prop="factoryName">
                   <el-input v-model="form.factoryName" placeholder="请输入公司名称" />
                 </el-form-item>
               </el-col>
             </el-row>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="物料编号" prop="itemCode">
              <el-input v-model="form.itemCode" placeholder="请输入物料编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料子编号" prop="itemId">
              <el-input v-model="form.itemId" placeholder="请输入物料子编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="物料名称" prop="itemName">
              <el-input v-model="form.itemName" placeholder="请输入物料名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物料名称（英文）" prop="itemNameEn">
              <el-input v-model="form.itemNameEn" placeholder="请输入物料名称（英文）" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物料单位" prop="unit">
              <el-select style="width:100%" v-model="form.unit" placeholder="请选择物料单位">
                <el-option
                  v-for="dict in dict.type.jc_iteminfo_unit"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="包装方式" prop="baozhuangType">-->
        <!--              <el-select style="width:100%" v-model="form.baozhuangType" placeholder="请选择包装方式">-->
        <!--                <el-option-->
        <!--                  v-for="dict in dict.type.jc_iteminfo_bz"-->
        <!--                  :key="dict.value"-->
        <!--                  :label="dict.label"-->
        <!--                  :value="dict.value"-->
        <!--                ></el-option>-->
        <!--              </el-select>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="包装数量" prop="baozhuangQty">-->
        <!--              <el-input v-model="form.baozhuangQty" placeholder="请输入包装数量" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="规格型号" prop="spec">
              <el-input v-model="form.spec" placeholder="请输入规格" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料分类" prop="classId">
              <el-select @change="getClass"  style="width: 100%" filterable v-model="form.classId" placeholder="请选择物料分类" >
                <el-option
                  v-for="dict in classOptions"
                  :key="dict.classId"
                  :label="dict.className"
                  :value="dict.classId"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="条码号" prop="tmh">
              <el-input v-model="form.tmh" placeholder="请输入条码号" />
            </el-form-item>
          </el-col>
          <!--          <el-col :span="12">-->
          <!--            <el-form-item label="物料大类" prop="classBigId">-->
          <!--              <el-select @change="getBigClass" style="width: 100%" filterable v-model="form.classBigId" placeholder="请选择物料大类" >-->
          <!--                <el-option-->
          <!--                  v-for="dict in classBigOptions"-->
          <!--                  :key="dict.wuliuDlCode"-->
          <!--                  :label="dict.wuliuDlName"-->
          <!--                  :value="dict.wuliuDlCode"-->
          <!--                />-->
          <!--              </el-select>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <el-col :span="12">
            <el-form-item label="请选择供应商" prop="supplyId">
              <el-select style="width: 100%" filterable v-model="form.supplyId" placeholder="供应商" >
                <el-option
                  v-for="dict in supplyOptions"
                  :key="dict.id"
                  :label="dict.supplierName"
                  :value="parseInt(dict.id)"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!--          <el-row>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="供应商简称" prop="supplyJc">-->
        <!--                <el-input v-model="form.supplyJc" placeholder="请输入供应商简称" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="预警上线" prop="upLine">-->
        <!--                <el-input v-model="form.upLine" placeholder="请输入预警上线" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="预警下线" prop="downLine">-->
        <!--              <el-input v-model="form.downLine" placeholder="请输入预警下线" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="中间值" prop="middleLine">-->
        <!--              <el-input v-model="form.middleLine" placeholder="请输入中间值" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="尺寸" prop="size">-->
        <!--              <el-input v-model="form.size" placeholder="请输入尺寸" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="物料状态" prop="stopFlag">-->
        <!--              <el-select v-model="form.stopFlag" placeholder="请选择物料状态">-->
        <!--                <el-option-->
        <!--                  v-for="dict in dict.type.jc_iteminfo_stop"-->
        <!--                  :key="dict.value"-->
        <!--                  :label="dict.label"-->
        <!--                  :value="parseInt(dict.value)"-->
        <!--                ></el-option>-->
        <!--              </el-select>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="存储期" prop="cunchudate">-->
        <!--              <el-input v-model="form.cunchudate" placeholder="请输入存储期" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="单重" prop="singleWeight">-->
        <!--              <el-input v-model="form.singleWeight" placeholder="请输入单重" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <!--          <el-row>-->

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="使用状态" prop="useState">-->
        <!--                <el-input v-model="form.useState" placeholder="请输入使用状态" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="颜色" prop="color">-->
        <!--                <el-input v-model="form.color" placeholder="请输入颜色" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--          <el-row>-->

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="花纹" prop="figure">-->
        <!--                <el-input v-model="form.figure" placeholder="请输入花纹" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="材质" prop="caizhi">-->
        <!--                <el-input v-model="form.caizhi" placeholder="请输入材质" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--          <el-row>-->


        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="托管状态" prop="isTuoguan">-->
        <!--                <el-select v-model="form.isTuoguan" placeholder="请选择物料状态">-->
        <!--                  <el-option-->
        <!--                    v-for="dict in dict.type.is_tuoguan"-->
        <!--                    :key="dict.value"-->
        <!--                    :label="dict.label"-->
        <!--                    :value="dict.value"-->
        <!--                  ></el-option>-->
        <!--                </el-select>-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--          <el-row>-->

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="计划价" prop="jhPrice">-->
        <!--                <el-input v-model="form.jhPrice" placeholder="请输入计划价" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="合同价" prop="htPrice">-->
        <!--                <el-input v-model="form.htPrice" placeholder="请输入合同价" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--          <el-row>-->

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="发票价" prop="fpPrice">-->
        <!--                <el-input v-model="form.fpPrice" placeholder="请输入发票价" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="结算价" prop="jsPrice">-->
        <!--                <el-input v-model="form.jsPrice" placeholder="请输入结算价" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--          <el-row>-->

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="生产周期" prop="proCycle">-->
        <!--                <el-input v-model="form.proCycle" placeholder="请输入生产周期" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="供货周期" prop="deliveryCycle">-->
        <!--                <el-input v-model="form.deliveryCycle" placeholder="请输入供货周期" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--          <el-row>-->

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="供货份额" prop="deliveryFe">-->
        <!--                <el-input v-model="form.deliveryFe" placeholder="请输入供货份额" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="份额调整比例" prop="adjustRate">-->
        <!--                <el-input v-model="form.adjustRate" placeholder="请输入份额调整比例" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--          <el-row>-->

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="份额调整日期" prop="adjustDate">-->
        <!--                <el-date-picker clearable-->
        <!--                                v-model="form.adjustDate"-->
        <!--                                type="date"-->
        <!--                                value-format="yyyy-MM-dd"-->
        <!--                                placeholder="请选择份额调整日期">-->
        <!--                </el-date-picker>-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="月订单数量" prop="yddNum">-->
        <!--                <el-input v-model="form.yddNum" placeholder="请输入月订单数量" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--          <el-row>-->

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="月完成数量" prop="ywcNum">-->
        <!--                <el-input v-model="form.ywcNum" placeholder="请输入月完成数量" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="月度供货未完成比率" prop="yghwwcRate">-->
        <!--                <el-input v-model="form.yghwwcRate" placeholder="请输入月度供货未完成比率" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--          <el-row>-->

        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="月完成数量" prop="ywcNum">-->
        <!--                <el-input v-model="form.ywcNum" placeholder="请输入月完成数量" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--            <el-col :span="12">-->
        <!--              <el-form-item label="保质期" prop="productiondate">-->
        <!--                <el-input v-model="form.productiondate" placeholder="请输入保质期" />-->
        <!--              </el-form-item>-->
        <!--            </el-col>-->
        <!--          </el-row>-->
        <!--        <el-row>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成本价" prop="price">
              <el-input v-model="form.price" placeholder="请输入成本价" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="物料识别码">
              <el-input v-model="form.itemIdentifyCode" placeholder="请输入物料识别码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="物料图片">
              <image-upload v-model="form.url"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 物料导入对话框 -->
    <el-dialog :close-on-click-modal="false" :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!--  <div class="el-upload__tip" slot="tip">
              <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
            </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <div style="display: none">
      <div id="printDan" ref="printDan">
        <div style="display: flex;flex-direction: column;padding-top:190px;font-size: 12px">
          <div style="display: flex;flex-direction: row">
            <div class="qrcode" ref="qrCodeUrl" style="margin-top: 20px;margin-left: 10px"></div>
            <div style="width: 65%;word-break: break-word;margin-left: 10px;margin-top: 10px;font-size: 18px">
              <div>物料名称：{{formDan.itemName}}</div>
              <div>物料单位：{{formDan.unit}}</div>
              <div>物料编号：{{formDan.itemCode}}</div>
              <div>物料分类编码：{{formDan.classId}}</div>
              <div>分类名称：{{formDan.className}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div style="width: 100mm;display: none">
      <div style="width: 100mm;display: flex;flex-wrap:wrap;margin:0;padding:0" id="printDan2" class="printDan2" ref="printDan2">
        <div class="itemBox" :style="{ pageBreakAfter: (jms.length-index)==1||(jms.length%2==0) ? 'auto' : 'always' }" style="width: 46%;justify-content: center;padding-left: 3mm;padding-top:3mm" v-for="(item,index) in jms" :key="index">
          <div class="imgBox" style="width: 100%">
            <img style="width: 90%;margin:0 auto" src="../../../assets/images/555.png" alt="">
          </div>
          <div style="width: 100%;margin-top: 5px;display: flex;justify-content: left">
            <div style="width: 20%" class="qrcode" ref="qrCodeUrl"></div>
            <div style="width: 80%;transform:scale(.6);margin-left: -2mm;margin-top: -4mm;display: flex;flex-direction: column;flex-wrap: wrap;font-size: 12px">
              <div>图号:{{item.itemName}}</div>
              <div>编号:{{item.itemCode}}</div>
              <div>型号:{{item.spec}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { listIteminfo, getIteminfo, delIteminfo,delAllItemInfo, addIteminfo, updateIteminfo } from "@/api/base/iteminfo";
  import { getToken } from "@/utils/auth";
  import { getListClass} from "@/api/base/class";
  import { getListBigClass} from "@/api/base/iteminfoClassBig";
  import { getLiSupplier} from "@/api/supplychain/supplier";
  import {getLodop} from "@/common/LodopFuncs";
  import QRCode from "qrcodejs2";
  import print from 'print-js';

  export default {
    name: "Iteminfo",
    dicts: ['jc_iteminfo_unit', 'jc_iteminfo_bz','jc_iteminfo_stop','is_tuoguan'],
    data() {
      var validateitemCode = (rule, value, callback) => {
        var reg = /^.{0,50}$/;
        if(!reg.test(value) && value!=undefined && value!=""){
          return callback(new Error('物料编号过长!'));
        } else{
          callback();
        }
      };

      var validateupLine = (rule, value, callback) => {
        var reg = /^\+?(0|[1-9][0-9]*)$/
        if(!reg.test(value) && value!=undefined && value!=""){
          return callback(new Error('预警值只能是整数!'));
        } else{
          callback();
        }
      };

      return {
        formDan:{},
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        jms:[],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 物料信息表格数据
        iteminfoList: [],
        options: [{
          value: '0',
          label: '下料线'
        }, {
          value: '1',
          label: '1吨线'
        }, {
          value: '2',
          label: '750线'
        }, {
          value: '3',
          label: '560线'
        }, {
          value: '4',
          label: '250线'
        }],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //分类类单位字典
        classOptions: [],
        //大类单位字典
        classBigOptions: [],
        //供应商字典
        supplyOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          deptId: null,
          itemName: null,
          itemNameEn: null,
          unit: null,
          baozhuangType: null,
          baozhuangQty: null,
          spec: null,
          model: null,
          tmh: null,
          classId: null,
          className: null,
          supplyId: null,
          supplyName: null,
          upLine: null,
          downLine: null,
          middleLine: null,
          stopFlag: null,
          cunchudate: null,
          productiondate: null,
          itemIdentifyCode:null,
        },
        // 表单参数
        form: {},

        // 物料导入参数
        upload: {
          // 是否显示弹出层（物料导入）
          open: false,
          // 弹出层标题（物料导入）
          title: "导入物料",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/base/iteminfo/importData"
        },

        // 表单校验
        rules: {
          /*  deptId: [
              { required: true, message: "部门id不能为空", trigger: "blur" }
            ],*/

          /*       prodLockNum: [
                   { required: true, message: "转生产数量不能为空!", trigger: "blur" },
                   { validator: valiprodLockNum,trigger: "blur" }
                 ],*/
          // classId: [
          //   { required: true, message: "请选择物料分类", trigger: "blur" },
          // ],
          itemCode: [
            { required: true, message: "物料编号不能为空", trigger: "blur" },
            { validator: validateitemCode,trigger: "blur" }
          ],

          itemName: [
            { required: true, message: "物料名称不能为空", trigger: "blur" },
            { validator: validateitemCode,trigger: "blur" }
          ],
          tmh: [
            { required: true, message: "条码号不能为空", trigger: "blur" },
            { validator: validateitemCode,trigger: "blur" }
          ],
          // price: [
          //   { required: true, message: "价格不能为空", trigger: "blur" },
          //   { validator: validateitemCode,trigger: "blur" }
          // ],

          upLine: [
            { validator: validateupLine,trigger: "blur" }
          ],

          downLine: [
            { validator: validateupLine,trigger: "blur" }
          ],


        }
      };
    },
    created() {
      this.getList();
      //物料分类
      getListClass().then(response => {
        this.classOptions = response.data;
      });
      //物料大类
      getListBigClass().then(response => {
        this.classBigOptions = response.data;
      });
      getLiSupplier().then(response => {
        this.supplyOptions = response.data;
      });

    },
    methods: {
      printt(){
        let LODOP = getLodop();
        LODOP.PRINT_INIT("");
        LODOP.PRINT_INITA(0,0,190,94,"");
        for(let i=0;i<this.jms.length;i++){

          LODOP.NewPage();
          LODOP.SET_PRINT_STYLE("FontSize",8);
          LODOP.SET_PRINT_PAGESIZE(1,500,250,"");
          LODOP.ADD_PRINT_BARCODE(21,2,87,134,"QRCode",this.jms[i].itemId);
          LODOP.ADD_PRINT_TEXT(30,80,90,20,"产品名:"+this.jms[i].itemName);
          LODOP.ADD_PRINT_TEXT(65,80,90,20,"产品码:"+this.jms[i].itemId);
          //    LODOP.PRINT();

        }


        LODOP.PREVIEW();
      },
      printtt(){
        this.$nextTick(()=>{
          this.jms.forEach((item,index)=>{
            let code = item.itemId;
            this.$refs.qrCodeUrl[index].innerHTML="";
            new QRCode(this.$refs.qrCodeUrl[index], {
              text: code, //二维码内容
              width: 50,
              height: 50,
              // colorDark: "#333333", //二维码颜色
              // colorLight: "#ffffff", //二维码背景色
            })
          })
          setTimeout(()=>{
            this.priDan2()
          },200)
        })
      },
      priDan2(){
        // this.$printPage(this.$refs.printDan2)
        const style = '@page { margin:10px 0 0 0 } ' +'@media print { #title{ font-size:12px};#title1{ font-size:12px };.name{font-size:10px}  }' ;
        printJS({
          printable:this.$refs.printDan2,
          type:'html',
          header:'',
          targetStyles:['*'],
          scanStyles: false,
          style:style,
          onPrintDialogClose: () => {
            console.log('弹窗关闭');
          },
          onLoadingEnd:()=>{
            console.log('加载完毕')
          }
        })
      },
      printt2(){
        const id = this.ids
        getIteminfo(id).then(response => {
          let CID = response.data.classId
          if(CID == 'Y'||CID == 'J'){
            this.formDan = response.data
            let data = response.data
            this.$refs.qrCodeUrl.innerHTML = "";
            var qrcode = new QRCode(this.$refs.qrCodeUrl, {
              text: data.itemId, // 需要转换为二维码的内容
              width: 120,
              height: 120,
              colorDark: '#000000',
              colorLight: '#ffffff',
              correctLevel: QRCode.CorrectLevel.H
            })
            this.$nextTick(()=>{
              this.priDan()
            })
          }else{
            this.$message.error('该物料不是原材料');
          }

        });
      },
      priDan(){
        // printBill
        // const style = '@page{margin:0};.title{fontSize:30px}'
        const style = '@page { margin:0 } ' +'@media print { #title{ font-size:20px};#title1{ font-size:20px }  ' ;
        printJS({
          printable:this.$refs.printDan,
          type:'html',
          header:'',
          targetStyles:['*'],
          scanStyles: false,
          style:style,
          onPrintDialogClose: () => {
            console.log('弹窗关闭');
          },
          onLoadingEnd:()=>{
            console.log('加载完毕')
          }
        })
      },
      /** 查询物料信息列表 */
      getList() {
        this.loading = true;
        listIteminfo(this.queryParams).then(response => {
          this.iteminfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },

      /** 下载模板操作 */
      importTemplate() {
        this.download('base/iteminfo/importTemplate', {
        }, `物料信息模板.xlsx`)
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      },

      //大类翻译
      classFormat(row, column) {
        var actions = [];
        Object.keys(this.classOptions).some((key) => {
          if (this.classOptions[key].classId == ('' + row.classId)) {
            actions.push(this.classOptions[key].className);
            return true;
          }
        })
        return actions.join('');
      },


      //供应商翻译
      supplyFormat(row, column) {
        var actions = [];
        Object.keys(this.supplyOptions).some((key) => {
          if (this.supplyOptions[key].id == ('' + row.supplyId)) {
            actions.push(this.supplyOptions[key].supplyName);
            return true;
          }
        })
        return actions.join('');
      },


      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          deptId: null,
          itemName: null,
          itemNameEn: null,
          unit: null,
          baozhuangType: null,
          baozhuangQty: null,
          spec: null,
          model: null,
          tmh: null,
          classId: null,
          className: null,
          supplyId: null,
          supplyName: null,
          upLine: null,
          downLine: null,
          middleLine: null,
          stopFlag: null,
          cunchudate: null,
          productiondate: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
        this.jms = selection.map((item) => {
          return{
            itemName:item.itemName,
            itemId:item.itemId,
            itemCode:item.itemCode,
            spec:item.spec
          }
        })
      },
      getClass(value){
        let selectedName = {};
        selectedName = this.classOptions.find((item)=>{
          return item.classId === value;
          //筛选出匹配数据，是对应数据的整个对象
        });
        this.form.className=selectedName.className;
      },
      getBigClass(value){
        let selectedName = {};
        selectedName = this.classBigOptions.find((item)=>{
          return item.wuliuDlCode === value;
          //筛选出匹配数据，是对应数据的整个对象
        });
        this.form.classBigName=selectedName.wuliuDlName;
      },

      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加物料信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getIteminfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改物料信息";
        });
      },
      handleDeleteAll(){
        this.$modal.confirm('是否确认全部删除数据？').then(function() {
          return delAllItemInfo();
        }).then(() => {
          this.getList();
          this.$modal.alertSuccess("删除成功");
        }).catch(() => {});
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateIteminfo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addIteminfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除物料信息编号为"' + ids + '"的数据项？').then(function() {
          return delIteminfo(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },

      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "物料导入";
        this.upload.open = true;
      },

      /** 导出按钮操作 */
      handleExport() {
        this.download('base/iteminfo/export', {
          ...this.queryParams
        }, `iteminfo_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
<style scoped>
  @media print {
    @page {
      size: auto;
      margin: 200px 50px;
    }
    .printDan2{
      height: 100%;
      font-weight: 500;
      font-size: 14px;
      position: absolute;
      width: 1000px;
      left: 0;
      top: 0;
      bottom: 0;
      margin: auto;
    }
  }

</style>
